package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.reggie.common.MyContext;
import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.AddressBook;
import com.itheima.reggie.mapper.AddressBookMapper;
import com.itheima.reggie.service.AddressBookService;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Service
public class AddressBookServiceImpl extends ServiceImpl<AddressBookMapper, AddressBook> implements AddressBookService {
    @Override
    public void setDefault(AddressBook addressBook) {

        Long userId = MyContext.getLoginId();
        //先把数据库里该用户的全部默认状态status为0


        LambdaUpdateWrapper<AddressBook> lqw1 = new LambdaUpdateWrapper<>();
        lqw1.eq(AddressBook::getUserId,userId)
                .set(AddressBook::getIsDefault,0);
        this.update(lqw1);
        //单独设置该地址的默认状态status为1

        addressBook.setIsDefault(1);

        this.updateById(addressBook);
    }





}
